//===================================================== select2 begin =======================================================
//初始化select2元素
var initSelect2Eles = function(ele, changeFn) {
	if (!jQuery().select2) {
		ShieldJS.error("检测到scroller元素缺少依赖JS库：select2.full.js！");
		return;
	}
	var pageSize = ele.data("pagesize")||20; //ajax分页时每页显示的条数
	var _default = { 
			multiple : false
			,language: "zh-CN"
			,minimumInputLength: -1 // 最少输入多少个字符后开始查询
//  		,allowClear: true
	};
	if (ele.data("nosearch")=="" || ele.data("nosearch")=="true") { //设置为不搜索
		_default.minimumResultsForSearch = -1; //不搜索，minimumInputLength为-1时
		_default.minimumInputLength = -1;
	}
	if (ele.data("ajax")) {
		_default.ajax = {
			url: ele.data("url"),
			dataType: 'json',
			data: function (params) {
				var query = { //请求的参数, 关键字和搜索条件之类的
					search: params.term //select搜索框里面的value
					,page: params.page||1
				}
				// Query paramters will be ?search=[term]&page=[page]
				query = $.extend(true, query, getParams(ele));
				return query;
			},
//      delay: 1500,
			processResults: function (data, params) {
				//返回的选项必须处理成以下格式
				//var results =  [{ id: 0, text: 'enhancement' }, { id: 1, text: 'bug' }, { id: 2, text: 'duplicate' }];
				var results=[];
				if (data.success) {
					results = data.object;
              }
				return {
					results: results  //必须赋值给results并且必须返回一个obj
					,pagination: {
						more: (params.page||1 * pageSize) < data.total||0
	             	}
				};
			}
			,cache: true
		} 
	}
	var options = getExtendSettings(ele, _default);
	var areaObj = ele.select2(options);
	if (ele.data("url")) { //通过url调用返回结果
		ele.empty(); //清空下拉框
		fillSelectOptions(ele, changeFn);
	}
	setVal_Select(ele);
}
var fillSelectOptions = function(ele, changeFn) {
	if (!ele.data("ajax")) { //排除原插件的ajax调用
		//绑定Ajax的内容
		if (ele.data("url")) {
			ele.empty();//清空下拉框
			ShieldJS.ajax.getJSON(ele.data("url"), {}, function (data) {
				if (data.success) {
					ele.append("<option value='0'>&nbsp;请选择……</option>");
					$.each(data.object, function (i, item) {
						ele.append("<option value='" + item.id + "'>&nbsp;" + item.text + "</option>");
					});
					setVal_Select(ele);
					if ($.isFunction(changeFn)) {
						ele.change(function() {
							changeFn(ele);
						});
					}
				} 
			});
		}
	}
}
ShieldJS.HtmlAction.addHTMLEleAction("select2Plugin", ":input.select2_plugin", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		dealEle.each(function() {
	        var $this = $(this);
	        initSelect2Eles($this);
      });
	}
},"Select2控件（select2.full）");
//===================================================== select2 end =======================================================
//翻页处理
ShieldJS.HtmlAction.addHTMLEleAction("paginationBox", ".paginationBox", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		dealEle.each(function() {
			var paginationE = $(this);
			var totalpage = paginationE.attr("total"); //总页数
	        paginationE.find('a[v]').click(function() {
	            var t = $(this);
	            var formE = t.closest('form');
	            var pageNumE = formE.find('.pageNum');
	            var pageNum = t.attr('v');
	            pageNum = checkpage(pageNum, totalpage);
	            pageNumE.val(pageNum);
	            formE.submit();
	        });
	        var gotoPage = function(t) {
	            var formE = t.closest('form');
	            var toPageNumE = formE.find('.toPageNum');

	            if (toPageNumE.val() == '') {
	            	ShieldJS.error('请输入页码！');
	                toPageNumE.focus();
	            } else {
	                var pageNumE = formE.find('.pageNum');
	                var pageNum = toPageNumE.val();
	                pageNum = checkpage(pageNum, totalpage);
	                if (/^\d+$/.test(pageNum)) {
	                    pageNumE.val(pageNum);
	                    formE.submit();
	                } else {
	                	ShieldJS.error('请输入数字！');
	                }
	            }
	        };

	        paginationE.find('.toPageNum').keydown(function(e) { //跳转到指定页数
	            if (e.which == ShieldJS.keyCode.ENTER ) { //回车 13
	                gotoPage($(this));
	                return false;
	            }
	        });
	        paginationE.find('.gotoPage').click(function() {
	            gotoPage($(this));
	        });
	        paginationE.addClass('inited');
		    
        });
		function checkpage(pageNum, totalpage) {
			if (pageNum - 1 < 0)
				pageNum = 1;
			if (pageNum - totalpage > 0)
				pageNum = totalpage;
			return pageNum;
		}
	}
}, "翻页处理");
ShieldJS.HtmlAction.addHTMLEleAction("autocompleteTips", ".autocompleteTips", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		dealEle.each(function() {
			var $this = $(this);
			var autocompleteDivE = contentE.find("#autocompleteDiv");
			if (autocompleteDivE.length == 0) {
				contentE.append('<div id="autocompleteDiv"></div>');
				autocompleteDivE = contentE.find("#autocompleteDiv");
            }
			autocompleteDivE.css("position", "absolute"); //绝对定位
			//ele.find(".addItemtable").hide();
			var ajaxpost;
			var index = -1; //下标，用于鼠标移动
			var options = getExtendSettings($this, {});
			var event = $this.data("event");
			if (event == "click") {
				$this.click(function(event){
					var thisObj = $(this);
					autocompleteDivE.show().offset({left:thisObj.offset().left, top:thisObj.offset().top+thisObj.height()+10});
					var val = thisObj.val().trim(); //需要现取
    				if(ajaxpost)
    					clearTimeout(ajaxpost);
    				ajaxpost = setTimeout(function(){
						autocompleteDivE.data("targetE", thisObj).load(thisObj.data("tipsUrl"), {time:1, name:val}).show();
						index = -1;
						return false;
    				}, 500); //延时0.5
            		return false;
            	});
            } else {
            	$this.keyup(function(event){
            		var thisObj = $(this);
            		autocompleteDivE.show().offset({left:thisObj.offset().left, top:thisObj.offset().top+thisObj.height()+10});
            		var key = event.which;
            		if (key == ShieldJS.keyCode.ENTER) { // 回车
            			autocompleteDivE.find(".selected").click();
            		} else if(key == ShieldJS.keyCode.UP) { // 上
            			var lis = autocompleteDivE.find("li");
            			index--;
            			if(index == -1){
            				index = lis.length-1;
            			}
            			autocompleteDivE.find("li").removeClass("selected");
            			contentE.find(autocompleteDivE.find("li").get(index)).addClass("selected");
            		} else if(key == ShieldJS.keyCode.DOWN) { // 下
            			var lis = $("#autocompleteDiv").find("li");
            			index++;
            			if(index == lis.length){
            				index = 0;
            			}
            			autocompleteDivE.find("li").removeClass("selected");
            			contentE.find(autocompleteDivE.find("li").get(index)).addClass("selected");
            		} else {
            			if((48<= key && key <= 111) || key == ShieldJS.keyCode.BLANK || key == ShieldJS.keyCode.BACKSPACE){ // 空格，回退键
            				var val = thisObj.val().trim(); //需要现取
            				if(ajaxpost)
            					clearTimeout(ajaxpost);
            				ajaxpost = setTimeout(function(){
            					if(val){
            						autocompleteDivE.data("targetE", thisObj).load(thisObj.data("tipsUrl"), {time:1, name:val}).show();
            						index = -1;
            						return false;
            					}
            				}, 500); //延时0.5
            				if(!$this.val()){ //值为空则清空并隐藏
            					autocompleteDivE.html("").hide();
            				}
            			}
            		}
            		return false;
            		
            	}).click(function(){
            		return false;
            	}).keydown(function(event){
            		var key = event.which;
            		if (key == 13){
            			return false;
            		}
            	});
            }
			autocompleteDivE.on("click", "li", function(){ //选择结果点击
				var jobj = $(this);
				var targetE = autocompleteDivE.data("targetE").closest("tr");
				var datas = jobj.data(); //用data存储
				for ( var key in datas) {
					targetE.find('[name="'+key+'"]').val(datas[key]);
					targetE.find('[value-to="'+key+'"]').val(datas[key]);
                }
				autocompleteDivE.hide();
				return false;
			});
			contentE.click(function(){ //点击空白关闭提示框
				autocompleteDivE.hide();
			});
        });
	}
}, "自动填充下拉提示插件");
// resetsortsEle排序值存放元素(jquery选择器)，resettips 排序提示语(字符) resettipsEle排序提示语显示元素(jquery选择器),resetbtnEle排序按钮(jquery选择器)
// 动态添加的行不能处理 TODO
ShieldJS.HtmlAction.addHTMLEleAction("tableDnD", ".tableDnD", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		if (!jQuery().tableDnD) {
	        ShieldJS.error("tableDnD插件不存在！");
        }
		// 如果某一些行不想拖动，只需要给这一行添加class nodrop和nodrag
		dealEle.each(function() {
			var $this = $(this);
			var options = getExtendSettings($this, {
				onDragClass: "myDragClass", //选中拖动一行时候的样式
				onDrop: function(table, row) { //表示拖动成功后执行的方法,要使用该方法tr上必须有id属性,该方法默认将tr的id作为取值
					var sortsESelector = $this.data("resetsortsEle")||"resetsorts";
					var sortsE = contentE.find(sortsESelector);
					if (sortsE.length > 0) {
						if(!sortsE.val()){
							var msg = $this.data("resettips")||"检测到列表中排序进行了改变，请记得更新排序！"
							var resettipsEleSelector = $this.data("resettipsEle")||"#resettips";
							if ($(resettipsEleSelector).length > 0) {
		 						$(resettipsEleSelector).text(msg); //页面内容中提示
		                    } else {
		                    	ShieldJS.alert("提示信息", msg, "info"); //提示框提示
		                    }
							var resetOrderbtnSelector = $this.data("resetbtnEle")||".resetOrderbtn";
							$(resetOrderbtnSelector).show();
						}
						var orders = "";
						var rows = table.tBodies[0].rows;
						for (var i=0; i<rows.length; i++) {
							orders += rows[i].id+",";
						}
						sortsE.val(orders);
					}
				},
				dragHandle: ".dragHandle",
				onDragStart: function(table, row) {console.log("123")} 
			});
			$this.tableDnD(options);
			$this.on("mouseover mouseout", "td.dragHandle",function(event){
				if(event.type == "mouseover"){
					//鼠标悬浮
					$(this).addClass('showDragHandle');
				}else if(event.type == "mouseout"){
					//鼠标离开
					$(this).removeClass('showDragHandle');
				}
			})//鼠标停留样式
			
        });
	}
}, "tableDnD拖拽插件");
ShieldJS.HtmlAction.addHTMLEleAction("checkboxSwitch", ".checkboxSwitch", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		dealEle.each(function() {
			var $this = $(this);
			//var options = getExtendSettings($this, {});
			var checkboxName = $this.attr("name");
			var checkedVal = $this.val()||1;
			var checked = $this.prop("checked");
			if ($this.prev(':input[name="'+checkboxName+'"]').length == 0) {
				$this.before('<input type="hidden" name="' + checkboxName + '" value="' + (checked ?checkedVal:'0') +'"/>');
            }
			$this.attr("name", checkboxName+"-switch");
			$this.on("click", function(){
				var $this = $(this);
				var checked = $this.prop("checked");
				$this.prev(":input").val(checked? checkedVal :"0");
			});
        });
	}
}, "checkbox的switch插件(选中1不选中0)");
ShieldJS.HtmlAction.addHTMLEleAction("operate_icon", ".operate_icon", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		dealEle.each(function() {
			var $this = $(this);
			
			var indexoperateE = $this.index(); //获取同类元素中的下标
			var operateTableE = $this.closest("table");
			var maxImgSize = 0;
			var dataMaxImgSize = operateTableE.data("maxImgSize"); //最多的图片个数，可能不同行的图片个数不一样
			if (dataMaxImgSize) {
				maxImgSize = dataMaxImgSize;
            } else {
            	operateTableE.find("tr").has("img").each(function(){
            		var operateTableTrE = $(this);
            		var imgLength = operateTableTrE.find("td:eq("+indexoperateE+")").find("img").length; //查找
            		if(imgLength > maxImgSize){
            			maxImgSize = imgLength;
            		}
            	});
            	operateTableE.data("maxImgSize", maxImgSize);
            	
            }
			var maxNumSet = operateTableE.data("maxNum"); //允许显示的最多个数
			if(maxNumSet && maxImgSize > maxNumSet){ //是否超过
				maxImgSize = maxNumSet; // 页面按钮数最多数。
			}
			operateTableE.find("tr").each(function(){
				var operateTableTrE = $(this);
				operateTableTrE.find("td:eq("+indexoperateE+")").addClass("operate_icon"+maxImgSize);
			});
			$this.addClass("operate_icon"+maxImgSize).css("min-width", maxImgSize*30);
        });
	}
}, "根据操作图标的个数修改样式");
ShieldJS.HtmlAction.addHTMLEleAction("fileUploadWebUploader", ".fileUploadWU_plugin", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		var $ = jQuery;
		dealEle.each(function() {
			var ele = $(this);
			var _default = {
				// 自动上传。
	        	auto: true,
	        	// swf文件路径
	        	swf: ctxPath+'/js/webuploader-0.1.5/Uploader.swf',
	        	// 文件接收服务端。
	        	server: uploadUeRootPath+'?action=uploadfile&encode=utf-8&sendRedirect='+uploadCallbackURL,
	        	fileNumLimit:'1',  //文件总数量只能选择1个 

	        	// 选择文件的按钮。可选。
	        	pick: {id:ele,  //选择文件的按钮
	            	multiple:false, 
	            	label: '点击选择文件'
	            }
			};
			var options = getExtendSettings(ele, _default);
			// Web Uploader实例
			// 初始化Web Uploader
			var uploader = WebUploader.create(options);


		 	// 文件上传过程中创建进度条实时显示。    uploadProgress事件：上传过程中触发，携带上传进度。 file文件对象 percentage传输进度 Nuber类型
		    uploader.on( 'uploadProgress', function( file, percentage ) {
		        var $li = $( '#'+file.id ),
		            $percent = $li.find('.progress span');

		        // 避免重复创建
		        if ( !$percent.length ) {
		            $percent = $('<p class="progress"><span></span></p>')
		                    .appendTo( $li )
		                    .find('span');
		        }

		        $percent.css( 'width', percentage * 100 + '%' );
		    });
		    var parE = ele.closest(".uploadContainer");
		    if (parE.length == 0) {
		    	parE = ele.parent();
		    }
		    var filePathE = parE.find(".filePath");
		    var fileNameE = parE.find(".fileName");
		    var fileIdE = parE.find(".fileId");
		    var fileOldIdE = parE.find(".fileIdOld");
		    var fileNameOldE = parE.find(".fileNameOld");
		    var listE = parE.find(".fileDiv").find("ul"); //新上传的
		    listE.on("click", ".del", function(){ // 点击×时，删除对应内容
		    	var $this = $(this);
		    	$(this).closest("li").remove();
                var affixPath = '';
                var affixName = '';
                var affixId='';
                var i = 0;
                listE.find("li").each(function(){
                    var thisAffixPath = $(this).attr("href");
                    var thisAffixName = $(this).attr("title");
                    var thisAffixId = $(this).attr("selfvalue");
                    if(thisAffixPath){
                    	if(i==0)
                		{
                    		affixPath = thisAffixPath;
                            affixName =  thisAffixName;
                            affixId  = thisAffixId;
                		}else
            			{
		        			affixPath += '#' + thisAffixPath;
		                    affixName += '#' + thisAffixName;
		                    affixId  += '#' + thisAffixId;
            			}
                    	
                    } else {
                    	affixPath = thisAffixPath;
                        affixName = thisAffixName;
                        affixId=thisAffixId;
                    }
                    i++;
                });
                fileIdE.val(affixId);
                filePathE.val(affixPath);
        		fileNameE.val(affixName);
		    });
		    var oldlistE = parE.find(".affixDiv").find("ul"); //原有的
		    oldlistE.on("click", ".del", function(){ // 点击×时，删除对应内容
		    	var $this = $(this);
		    	$(this).closest("li").remove();
		    	var affixId = '';
                var affixName = '';
                oldlistE.find("li").each(function(){
                	 var thisAffixId = $(this).attr("selfvalue");
                     var thisAffixName = $(this).attr("title");
                     if(affixId){
                         affixId = affixId + '#' + thisAffixId;
                         affixName = affixName + '#' + thisAffixName;
                     } else {
                         affixId = thisAffixId;
                         affixName = thisAffixName;
                     }
                });
                fileOldIdE.val(affixId);
                fileNameOldE.val(affixName);
		    });

		    // 文件上传成功时候触发，给item添加成功class, 用样式标记上传成功。 file：文件对象，response：服务器返回数据
		    uploader.on( 'uploadSuccess', function( file, response) { // response._raw 文本对象
		        $( '#'+file.id ).addClass('upload-state-done');
		        //console.info(response);
		        var append = ele.data("append");
		        if (response && response.state=="SUCCESS") {
		        	if (append) {
		        		var pathOld = filePathE.val()?(filePathE.val()+'#'):'';
		        		var nameOld = fileNameE.val()?(fileNameE.val()+'#'):'';
		        		var idOld = fileIdE.val()?(fileIdE.val()+'#'):'';
		        		filePathE.val(pathOld+response.url);
		        		fileNameE.val(nameOld+response.original);
		        		fileIdE.val(idOld+response.affixId);
		        		listE.append('<li class="multi-li" selfvalue="'+response.affixId+'" title="'+response.original+'" href='+response.url+'>'+response.original+'&nbsp;&nbsp;&nbsp;<a href="'+response.url+'"  '+
		        				' target="_blank" download="'+response.original+'">下载</a>&nbsp;&nbsp;&nbsp;<img class="multi-liimg del" src="'+ctxPath+'/images/icon/delete.png" title="点击取消"></li>')
                    } else {
                    	filePathE.val(response.url);
                    	fileNameE.val(response.original);
                    	fileIdE.val(response.affixId);
						
					}
		        	
	            }
		      	// ShieldJS.alert("提示", "上传成功", "info");

		    });

		    // 文件上传失败                                file:文件对象 ， code：出错代码
		    uploader.on( 'uploadError', function(file, code) {
		    	alert(code);
		        var $error = ele.find('div.error');
		        // 避免重复创建
		        if ( $error.length ) {
		        	$error.text('上传失败! ');
		        }
		        ShieldJS.alert("提示", "上传失败!", "error");
		    });

		    // 不管成功或者失败，文件上传完成时触发。 file： 文件对象
		    uploader.on( 'uploadComplete', function( file ) {
		        $( '#'+file.id ).find('.progress').remove();
		    });

		 	// 所有文件上传成功后调用        
		    uploader.on('uploadFinished', function () {
		        //清空队列
		         uploader.reset();
		    });
		  	//只允许上传一个，每次文件加入队列前触发
		    uploader.on('beforeFileQueued',function(){
		        uploader.reset();
		        uploader.refresh();
		    });

		    //绑定提交事件
		    //$("#upload").click(function() {
		        console.log("上传...");
		        //uploader.upload();   //执行手动提交
			//});
        });
	}
}, "文件上传（WebUploader版）");
ShieldJS.HtmlAction.addHTMLEleAction("imageUploadWebUploader", ".imageUploadwu_plugin", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		var $ = jQuery;
		dealEle.each(function() {
			var ele = $(this);
			var _default = {
				// 自动上传。
	        	auto: true,
	        	// swf文件路径
	        	swf: ctxPath+'/js/webuploader-0.1.5/Uploader.swf',
	        	// 文件接收服务端。
	        	server: uploadUeRootPath+'?action=uploadimage&encode=utf-8&sendRedirect='+uploadCallbackURL,
	        	fileNumLimit:'1',  //文件总数量只能选择1个 

	        	// 选择文件的按钮。可选。
	        	pick: {id:ele,  //选择文件的按钮
	            	multiple:false, 
	            	label: '点击选择图片'
	            },
				//限制传输文件类型，accept可以不写 
	        	accept: {
	            	title: 'Images',//描述
	            	extensions: 'gif,jpg,jpeg,png',//类型
	            	mimeTypes: '.gif,.jpg,.jpeg,.png'//mime类型
	        	}	
			};
			var options = getExtendSettings(ele, _default);
			// Web Uploader实例
			// 初始化Web Uploader
			var uploader = WebUploader.create(options);


		 	// 文件上传过程中创建进度条实时显示。    uploadProgress事件：上传过程中触发，携带上传进度。 file文件对象 percentage传输进度 Nuber类型
		    uploader.on( 'uploadProgress', function( file, percentage ) {
		        var $li = $( '#'+file.id ),
		            $percent = $li.find('.progress span');

		        // 避免重复创建
		        if ( !$percent.length ) {
		            $percent = $('<p class="progress"><span></span></p>')
		                    .appendTo( $li )
		                    .find('span');
		        }

		        $percent.css( 'width', percentage * 100 + '%' );
		    });

		    // 文件上传成功时候触发，给item添加成功class, 用样式标记上传成功。 file：文件对象，response：服务器返回数据
		    uploader.on( 'uploadSuccess', function( file, response) { // response._raw 文本对象
		        $( '#'+file.id ).addClass('upload-state-done');
		        //console.info(response);
		        if (response && response.state=="SUCCESS") {
		        	var parE = ele.closest(".uploadContainer");
		        	if (parE.length == 0) {
		        		parE = ele.parent();
                    }
		        	parE.find(".imgPath").val(response.url);
		        	parE.find(".imgShow").attr("src", response.url);
	            }
		      	// ShieldJS.alert("提示", "上传成功", "info");

		    });

		    // 文件上传失败                                file:文件对象 ， code：出错代码
		    uploader.on( 'uploadError', function(file, code) {
		        var $error = ele.find('div.error');
		        // 避免重复创建
		        if ( $error.length ) {
		            $error.text('上传失败! ');
		        }
		        ShieldJS.alert("提示", "上传失败!", "error");
		    });

		    // 不管成功或者失败，文件上传完成时触发。 file： 文件对象
		    uploader.on( 'uploadComplete', function( file ) {
		        $( '#'+file.id ).find('.progress').remove();
		    });

		 	// 所有文件上传成功后调用        
		    uploader.on('uploadFinished', function () {
		        //清空队列
		         uploader.reset();
		    });
		  	//只允许上传一个，每次文件加入队列前触发
		    uploader.on('beforeFileQueued',function(){
		        uploader.reset();
		        uploader.refresh();
		    });

		    //绑定提交事件
		    //$("#upload").click(function() {
		        console.log("上传...");
		        //uploader.upload();   //执行手动提交
			//});
        });
	}
}, "图片上传（WebUploader版）");
ShieldJS.HtmlAction.addHTMLEleAction("fileUpload", ".fileUpload", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		var $ = jQuery;
		dealEle.each(function() {
			var ele = $(this);
			var append = ele.data("append"); //追加多文件
			var fileNumber = 0; // 文件上传的次数
			var _default = {  		//默认配置参数
					'name' : 'file',   //上传时流的文件名称
					'fileType' : 'file',  //上传 类型     目前可选参数   (images:图片 ,file:文件)
					'exts' : 'jpg|png|bmp|jpeg|gif|JPG|PNG|BMP|GIF|JPEG|rar|zip|txt|doc|DOC|docx|DOCX|XLS|xls|xlsx|XLSX|PDF|pdf', //上传文件的后缀 限制  自定义
					'uploadURL' : uploadUeRootPath+'/redirect?action=uploadfile&encode=utf-8&sendRedirect='+uploadCallbackURL + '&uploadGroup='+uploadGroup, //上传的路径     详情见mytags.jsp  有默认参数
					'uploadButton' : '#uploadButton', //需要绑定上传的按钮，建议用id参数
					'fileNumber' : 1 // 默认限制1个
				};
			var options = getExtendSettings(ele, _default);
			// 删除计数器
			$(document).on("click", options.deleteUpload, function() {
				var $this = $(this);
				$this.closest("div").empty(); // 删除div
				fileNumber = fileNumber - 1;
			});
			var defaultURL = uploadUeRootPath+'/redirect?action=uploadfile&encode=utf-8&sendRedirect='+uploadCallbackURL + '&uploadGroup='+uploadGroup;

		    var parE = ele.closest(".uploadContainer");
		    if (parE.length == 0) {
		    	parE = ele.parent();
		    }
		    var filePathE = parE.find(".filePath");
		    var fileNameE = parE.find(".fileName");
		    var fileIdE = parE.find(".fileId");
		/*    var fileOldIdE = parE.find(".fileIdOld");
		    var fileNameOldE = parE.find(".fileNameOld");*/
		    var listE = parE.find(".fileDiv").find("ul"); //新上传的
		    listE.on("click", ".del", function(){ // 点击×时，删除对应内容
		    	var $this = $(this);
		    	$(this).closest("li").remove();
                var affixPath = '';
                var affixName = '';
                var affixId='';
                var i = 0;
                listE.find("li").each(function(){
                    var thisAffixPath = $(this).attr("href");
                    var thisAffixName = $(this).attr("title");
                    var thisAffixId = $(this).attr("selfvalue");
                    if(thisAffixPath){
                    	if(i==0)
                		{
                    		affixPath = thisAffixPath;
                            affixName =  thisAffixName;
                            affixId  = thisAffixId;
                		}else
            			{
		        			affixPath += '#' + thisAffixPath;
		                    affixName += '#' + thisAffixName;
		                    affixId  += '#' + thisAffixId;
            			}
                    	
                    } else {
                    	affixPath = thisAffixPath;
                        affixName = thisAffixName;
                        affixId=thisAffixId;
                    }
                    i++;
                });
                fileIdE.val(affixId);
                filePathE.val(affixPath);
        		fileNameE.val(affixName);
		    });
/*		    var oldlistE = parE.find(".fileDiv").find("ul"); //原有的
		    oldlistE.on("click", ".del", function(){ // 点击×时，删除对应内容
		    	console.log("原有的");
		    	var $this = $(this);
		    	$(this).closest("li").remove();
		    	var affixId = '';
                var affixName = '';
                oldlistE.find("li").each(function(){
                	 var thisAffixId = $(this).attr("selfvalue");
                     var thisAffixName = $(this).attr("title");
                     if(affixId){
                         affixId = affixId + '#' + thisAffixId;
                         affixName = affixName + '#' + thisAffixName;
                     } else {
                         affixId = thisAffixId;
                         affixName = thisAffixName;
                     }
                });
                fileIdE.val(affixId);
                fileNameE.val(affixName);
		    });*/

		    new AjaxUpload(ele, {
				// 文件上传地址 action
				// ://http://upload.credithegs.gov.cn/affixUpload?callback=http://localhost:8081/uploadCallback&serverLocation=&type=2
				// 图片上传你地址 action : settings.uploadUeRootPath +
				// "?action=uploadimage&sendRedirect=" + ctxPath + "/" +
				// settings.uploadCallbackURL,
				action : options.uploadURL||defaultURL,
				name : options.name,
				onSubmit : function(file, ext) {
					if (fileNumber > Number(options.fileNumber)) { // 先校验个数
						ShieldJS.alert("提示", "上传失败，超过最大个数" + fileNumber, "error");
						return false;
					}
					if ("images" == options.fileType) {
						if (options.exts != "*") {
							if (ext && new RegExp("^(" + options.exts + ")$").test(ext)) {
								this.setData({
									'info' : '文件类型为图片'
								});
							} else {
								ShieldJS.alert("提示", '文件格式错误，请上传格式为' + options.exts + ' 的图片', "error");
								return false;
							}
						}

					} else if ("file" == options.fileType) {
						if (options.exts != "*") {
							if (ext && new RegExp("^(" + options.exts + ")$").test(ext)) {
								this.setData({
									'info' : '文件类型'
								});
							} else {
								ShieldJS.alert("提示", '文件格式错误，请上传格式为' + options.exts + ' 的文件', "error");
								return false;
							}
						}
					} else {
						ShieldJS.alert("提示", 'fileType参数错误！', "error");
						return false;
					}
					index = layer.load(2);
					this.disable();

				},
				onComplete : function(file, response) {
					layer.close(index);
					try {
						var response = $.parseJSON(response); //返回的response为字符串重新处理为json
						if (response && response.state=="SUCCESS") {
				        	if (append) {
				        		var pathOld = filePathE.val()?(filePathE.val()+'#'):'';
				        		var nameOld = fileNameE.val()?(fileNameE.val()+'#'):'';
				        		var idOld = fileIdE.val()?(fileIdE.val()+'#'):'';
				        		filePathE.val(pathOld+response.url);
				        		fileNameE.val(nameOld+response.original);
				        		fileIdE.val(idOld+response.affixId);
				        		listE.append('<li class="multi-li" selfvalue="'+response.affixId+'" title="'+response.original+'" href='+response.url+'>'+response.original+'&nbsp;&nbsp;&nbsp;<a href="'+response.url+'"  '+
				        				' target="_blank" download="'+response.original+'">下载</a>&nbsp;&nbsp;&nbsp;<img class="multi-liimg del" src="'+ctxPath+'/images/icon/delete.png" title="点击取消"></li>')
		                    } else {
		                    	filePathE.val(response.url);
		                    	fileNameE.val(response.original);
		                    	fileIdE.val(response.affixId);
		                    	listE.html('<li class="multi-li" selfvalue="'+response.affixId+'" title="'+response.original+'" href='+response.url+'>'+response.original+'&nbsp;&nbsp;&nbsp;<a href="'+response.url+'"  '+
				        				' target="_blank" download="'+response.original+'">下载</a>&nbsp;&nbsp;&nbsp;<img class="multi-liimg del" src="'+ctxPath+'/images/icon/delete.png" title="点击取消"></li>')
							}
				        	
			            }else
		            	{
			            	layer.alert(response.state, {
								icon : 2
							});
		            	}
						this.enable();
					} catch (e) {
						console.log(e);
						//error(e, response);
					}
				},
				onError:function(e)
				{
					layer.close(index);
					layer.alert("上传的附加太大，超过限制！", {
						icon : 2
					});
					this.enable();
				}
			});
        });
	}
}, "文件上传（AjaxUpload版）");
ShieldJS.HtmlAction.addHTMLEleAction("imageUpload", ".imageUpload", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		var $ = jQuery;
		dealEle.each(function() {
			var ele = $(this);
			var append = ele.data("append"); //追加多文件
			var fileNumber = 0; // 文件上传的次数
			var _default = {  		//默认配置参数
					'name' : 'file',   //上传时流的文件名称
					'fileType' : 'images',  //上传 类型     目前可选参数   (images:图片 ,file:文件)
					'exts' : 'jpg|png|bmp|jpeg|gif|JPG|PNG|BMP|GIF|JPEG', //上传文件的后缀 限制  自定义
					'uploadURL' : uploadUeRootPath+'/redirect?action=uploadimage&encode=utf-8&sendRedirect='+uploadCallbackURL + '&uploadGroup='+uploadGroup, //上传的路径     详情见mytags.jsp  有默认参数
					'uploadButton' : '#uploadButton', //需要绑定上传的按钮，建议用id参数
					'fileNumber' : 1 // 默认限制1个
				};
			var options = getExtendSettings(ele, _default);
			// 删除计数器
			$(document).on("click", options.deleteUpload, function() {
				var $this = $(this);
				$this.closest("div").empty(); // 删除div
				fileNumber = fileNumber - 1;
			});
			
		   	var parE = ele.closest(".uploadContainer");
        	if (parE.length == 0) {
        		parE = ele.parent();
            }
        	
        	var filePathE = parE.find(".imgPath");
        	 var listE = parE.find(".img"); //新上传的
			new AjaxUpload(ele, {
				// 文件上传地址 action
				// ://http://upload.credithegs.gov.cn/affixUpload?callback=http://localhost:8081/uploadCallback&serverLocation=&type=2
				// 图片上传你地址 action : settings.uploadUeRootPath +
				// "?action=uploadimage&sendRedirect=" + ctxPath + "/" +
				// settings.uploadCallbackURL,
				action : options.uploadURL,
				name : options.name,
				onSubmit : function(file, ext) {
					if (fileNumber > Number(options.fileNumber)) { // 先校验个数
						layer.alert("上传失败，超过最大个数" + fileNumber);
						return false;
					}
					if ("images" == options.fileType) {
						if (options.exts != "*") {
							if (ext && new RegExp("^(" + options.exts + ")$").test(ext)) {
								this.setData({
									'info' : '文件类型为图片'
								});
							} else {
								// alert()
								layer.alert('文件格式错误，请上传格式为' + options.exts + ' 的图片', {
									icon : 7
								});
								return false;
							}
						}

					} else if ("file" == options.fileType) {
						if (options.exts != "*") {
							if (ext && new RegExp("^(" + options.exts + ")$").test(ext)) {
								this.setData({
									'info' : '文件类型'
								});
							} else {
								layer.alert('文件格式错误，请上传格式为' + options.exts + '的文件', {
									icon : 7
								});
								return false;
							}
						}
					} else {
						layer.alert('fileType参数错误！', {
							icon : 2
						});
						return false;
					}
					index = layer.load(2);
					this.disable();

				},
				onComplete : function(file, response) {
					layer.close(index);
					try {
						var response = $.parseJSON(response); //返回的response为字符串重新处理为json
						console.log(response);
						if (response && response.state=="SUCCESS") {
							console.log(append);
							if (append) {
				        		var pathOld = filePathE.val()?(filePathE.val()+'#'):'';
				        		filePathE.val(pathOld+response.url);
				        		if(parE.find(".nopic").length!=0)
			        			{
				        			parE.find(".imgShow").attr("src", response.url);
				        			parE.find(".nopic").removeClass("nopic");
				        		 	parE.find(".imgShow").after('<div style="text-align: center;" class="delimageNews" ><a>删除</a></div>');
			        			}else
		        				{
			        				listE.append('<div style="float:left;"><img  class="imgShow" name="imageNews" width="70" height="70" src="'+response.url+'" style="margin: 0 5px 10px; border: 1px solid #eee;  ">  <div style="text-align: center;" class="delimageNews" ><a>删除</a></div></div>')
		        				}
		                    } else {
					        	parE.find(".imgPath").val(response.url);
					        	parE.find(".imgShow").attr("src", response.url);
					        	if(parE.find(".imgShow").next('.delimageNews').length==0)
				        		{
					        		parE.find(".imgShow").after('<div style="text-align: center;" class="delimageNews" ><a>删除</a></div>');
				        		}
							}
			            }else
			            	{
				            	layer.alert(response.state, {
									icon : 2
								});
			            	}
						this.enable();
					} catch (e) {
						console.log(e);
						//error(e, response);
					}
				},
				onError:function(e)
				{
					layer.close(index);
					layer.alert("上传的图片太大，超过限制！", {
						icon : 2
					});
					this.enable();
				}
			});
			parE.on('click','.delimageNews',function(){
				var delimageNews = parE.find(".delimageNews");
				var imgShow = parE.find(".imgShow");
				var thisIndex = delimageNews.index($(this));
				delimageNews.eq(thisIndex).remove();
				imgShow.eq(thisIndex).remove();
				//
				var imgPathSrc ="";
				parE.find(".imgShow").each(function(i){
					var srcPath = $(this).attr("src");
				  if(srcPath){
                    	if(i==0)
                		{
                    		imgPathSrc = srcPath;
                		}else
            			{
                			imgPathSrc += '#' + srcPath;
            			}
                    }
				})
				if(!imgPathSrc)
				{
					listE.append('<img  class="imgShow nopic" name="imageNews" width="70" src="'+ctxPath+'/images/project/nopic.jpg" style="border: 1px solid #eee;" >')
				}
				parE.find(".imgPath").val(imgPathSrc);
			});
			
        });
	}
}, "图片上传（AjaxUpload版）");
ShieldJS.HtmlAction.addHTMLEleAction("download", ".download", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		var $ = jQuery;
		dealEle.each(function() {
			var ele = $(this);
			ele.click(function() {
	            var eleData = ele.data();
	            var _default = {
    				// 判断是否存在地址
            		url: ctxPath +'/isExitDownFile',
    	        	// 下载文件地址
            		downUrl: ctxPath +'/downloadAtt'
    			};
	    		var options = getExtendSettings(ele, _default);
	            var params = {};
	            params = getParams(ele, params);
	            var id = ele.attr('id');
	            if (!id) {
	            	id =  params.id;
                }
	            params.id = id;
	            ShieldJS.ajax.getJSON(options.url, params, function(data) {
	                window.location.href = options.downUrl + '?id=' + id;
	            });
	        });
        });
	}
}, "根据文件id下载文件");



ShieldJS.HtmlAction.addHTMLEleAction("localfileUpload", ".localfileUpload", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		var $ = jQuery;
		dealEle.each(function() {
			var ele = $(this);
			var _default = {
				// 自动上传。
	        	auto: true,
	        	// swf文件路径
	        	swf: ctxPath+'/js/webuploader-0.1.5/Uploader.swf',
	        	// 文件接收服务端。
	        	server: ctxPath+'/uploadFile',
	        	fileNumLimit:'1',  //文件总数量只能选择1个 

	        	// 选择文件的按钮。可选。
	        	pick: {id:ele,  //选择文件的按钮
	            	multiple:false, 
	            	label: '点击选择文件'
	            }
			};
			var options = getExtendSettings(ele, _default);
			// Web Uploader实例
			// 初始化Web Uploader
			var uploader = WebUploader.create(options);


		 	// 文件上传过程中创建进度条实时显示。    uploadProgress事件：上传过程中触发，携带上传进度。 file文件对象 percentage传输进度 Nuber类型
		    uploader.on( 'uploadProgress', function( file, percentage ) {
		        var $li = $( '#'+file.id ),
		            $percent = $li.find('.progress span');

		        // 避免重复创建
		        if ( !$percent.length ) {
		            $percent = $('<p class="progress"><span></span></p>')
		                    .appendTo( $li )
		                    .find('span');
		        }

		        $percent.css( 'width', percentage * 100 + '%' );
		    });
		    var parE = ele.closest(".uploadContainer");
		    if (parE.length == 0) {
		    	parE = ele.parent();
		    }
		    var filePathE = parE.find(".filePath");
		    var fileNameE = parE.find(".fileName");
		    var fileIdE = parE.find(".fileId");
		   // var fileNameOldE = parE.find(".fileNameOld");
		    var listE = parE.find(".fileDiv").find("ul"); //新上传的
		    listE.on("click", ".del", function(){ // 点击×时，删除对应内容
		    	var $this = $(this);
		    	$(this).closest("li").remove();
                var affixPath = '';
                var affixName = '';
                var affixId='';
                var i = 0;
                listE.find("li").each(function(){
                    var thisAffixPath = $(this).attr("href");
                    var thisAffixName = $(this).attr("title");
                    var thisAffixId = $(this).attr("selfvalue");
                    if(thisAffixPath){
                    	if(i==0)
                		{
                    		affixPath = thisAffixPath;
                            affixName =  thisAffixName;
                            affixId  = thisAffixId;
                		}else
            			{
		        			affixPath += '#' + thisAffixPath;
		                    affixName += '#' + thisAffixName;
		                    affixId  += '#' + thisAffixId;
            			}
                    	
                    } else {
                    	affixPath = thisAffixPath;
                        affixName = thisAffixName;
                        affixId=thisAffixId;
                    }
                    i++;
                });
                fileIdE.val(affixId);
                filePathE.val(affixPath);
        		fileNameE.val(affixName);
		    });
	/*	    var oldlistE = parE.find(".affixDiv").find("ul"); //原有的
		    oldlistE.on("click", ".del", function(){ // 点击×时，删除对应内容
		    	var $this = $(this);
		    	$(this).closest("li").remove();
		    	var affixId = '';
                var affixName = '';
                oldlistE.find("li").each(function(){
                	 var thisAffixId = $(this).attr("selfvalue");
                     var thisAffixName = $(this).attr("title");
                     if(affixId){
                         affixId = affixId + '#' + thisAffixId;
                         affixName = affixName + '#' + thisAffixName;
                     } else {
                         affixId = thisAffixId;
                         affixName = thisAffixName;
                     }
                });
                alert(affixName)
                fileIdE.val(affixId);
                fileNameOldE.val(affixName);
                alert(fileNameOldE.val())
		    });*/

		    // 文件上传成功时候触发，给item添加成功class, 用样式标记上传成功。 file：文件对象，response：服务器返回数据
		    uploader.on( 'uploadSuccess', function( file, response) { // response._raw 文本对象
		        $( '#'+file.id ).addClass('upload-state-done');
		        //console.info(response);
		        var append = ele.data("append");
		        console.log(ctxPath);
		        if (response && response.state=="SUCCESS") {
		        	if (append) {
		        		var pathOld = filePathE.val()?(filePathE.val()+'#'):'';
		        		var nameOld = fileNameE.val()?(fileNameE.val()+'#'):'';
		        		var idOld = fileIdE.val()?(fileIdE.val()+'#'):'';
		        		filePathE.val(pathOld+response.url);
		        		fileNameE.val(nameOld+response.original);
		        		fileIdE.val(idOld+response.affixId);
		        		listE.append('<li class="multi-li" selfvalue="'+response.affixId+'" title="'+response.original+'" href='+response.url+'>'+response.original+'&nbsp;&nbsp;&nbsp;<a href="'+response.url+'"  '+
		        				' target="_blank" download="'+response.original+'">下载</a>&nbsp;&nbsp;&nbsp;<img class="multi-liimg del" src="'+ctxPath+'/images/icon/delete.png" title="点击取消"></li>')
                    } else {
                    	filePathE.val(response.url);
                    	fileNameE.val(response.original);
                    	fileIdE.val(response.affixId);
						
					}
		        	
	            }
		      	// ShieldJS.alert("提示", "上传成功", "info");

		    });

		    // 文件上传失败                                file:文件对象 ， code：出错代码
		    uploader.on( 'uploadError', function(file, code) {
		    	alert(code);
		        var $error = ele.find('div.error');
		        // 避免重复创建
		        if ( $error.length ) {
		        	$error.text('上传失败! ');
		        }
		        ShieldJS.alert("提示", "上传失败!", "error");
		    });

		    // 不管成功或者失败，文件上传完成时触发。 file： 文件对象
		    uploader.on( 'uploadComplete', function( file ) {
		        $( '#'+file.id ).find('.progress').remove();
		    });

		 	// 所有文件上传成功后调用        
		    uploader.on('uploadFinished', function () {
		        //清空队列
		         uploader.reset();
		    });
		  	//只允许上传一个，每次文件加入队列前触发
		    uploader.on('beforeFileQueued',function(){
		        uploader.reset();
		        uploader.refresh();
		    });

		    //绑定提交事件
		    //$("#upload").click(function() {
		        console.log("上传...");
		        //uploader.upload();   //执行手动提交
			//});
        });
	}
}, "本项目文件上传");
ShieldJS.HtmlAction.addHTMLEleAction("imgPreviewPlugin", ".imgPreview_plugin", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		if(typeof toolTip == "undefined"){ //判断lunar是否已经定义
			ShieldJS.error("检测到imgPreview_plugin插件缺少依赖JS库：toolTip.js！");
			return false;
		}
		dealEle.each(function() {
			var selectEthis = $(this);
			selectEthis.hover(function(){
				var winHeight = $(window).height();
				var imgsrc = this.src;
				if(!imgsrc){
					imgsrc = $(this).attr("source");
				}
				toolTip("<img src='"+imgsrc+"'/>");
				$("#toolTip_container").find("img").load(function() {
					var imgHeight = $("#toolTip_container").find("img").height();
					if(imgHeight && winHeight<imgHeight){
						$("#toolTip_container").find("img").height(winHeight-60);
					}
				});
			}, function(){
				toolTip();
			});
		});
	}
}, "图片预览（鼠标悬停时放大显示）");
ShieldJS.HtmlAction.addHTMLEleAction("highlightjsPlugin", ".highlightjs_plugin", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		if(typeof hljs == "undefined"){ //判断hljs是否已经定义
			ShieldJS.error("检测到highlightjs_plugin插件缺少依赖JS库：highlight.js！");
			return false;
		}
		dealEle.each(function() {
			var selectEthis = $(this);
			//var options = getExtendSettings($this, {});
			selectEthis.find("pre").each(function(i, block) {
				hljs.highlightBlock(block);
			});
		});
    }
}, "highlight代码高亮");

ShieldJS.HtmlAction.addHTMLEleAction("sideTogglePlugin", ".sideToggle_plugin", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		
		 //默认配置 
		 var _default={
			moving: '#sideMenuContainer',
			direction: 'right',
			content:"#resultContent",
			width:"290"
		 }

		 var sideMenuContainerEle =  findAndMarkEle(contentE, "#sideMenuContainer");
		  //动态创建侧边栏html区域，判断是否已经创建过，创建过就不再创建
		 if (sideMenuContainerEle.length==0)
		 {
			 sideMenuContainerEle = $("<div id='sideMenuContainer'><div><a href='javascript:void(0);' style='cursor: pointer;' id='sideMenuContainerClose'>关闭</a></div><div id='resultContent'></div></div>")
			 sideMenuContainerEle.css({"box-shadow":" -3px 5px 5px #bbb","overflow-y": "auto","background":"#fff","height":"90%","padding":"10px","position":"fixed","top":"80px","right":"-"+(_default.width+20)+"px","width":""+_default.width+"px","z-index":"888"});
			 $(contentE).append(sideMenuContainerEle); 
			 //关闭侧边栏
			 sideMenuContainerEle.find("#sideMenuContainerClose").click(function(){
			      var thisDir = {};
			      var menuWidth = $(_default.moving).outerWidth();
			      thisDir[_default.direction] = -menuWidth;
			      $(_default.moving).animate(thisDir);
			 });
		 }
		
		 dealEle.each(function() {
			 var $this = $(this);
			 initsideTogglePluginEles($this, _default);
		 });
	}
}, "sideTogglePlugin控件,侧边栏");

var initsideTogglePluginEles = function(ele,_default) {
	if (!jQuery().sideToggle) {
		ShieldJS.error("检测到sideTogglePlugin元素缺少依赖JS库：sideToggleExtended.js！");
		return;
	}
	var params = {};
	var options = getExtendSettings(ele, _default);
	options.url = ele.data("url");
	options.params = getParams(ele, params);
	//初始化侧边栏
	$(ele).sideToggle(options);
}

//=================时间倒计时插件===========================
ShieldJS.HtmlAction.addHTMLEleAction("countDownPlugin", ".countDown_plugin", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		dealEle.each(function() {
	        var $this = $(this);
	        initCountDownEles($this);
      });
	}
},"countDown倒计时插件控件");

//初始化countDown元素
var initCountDownEles = function(ele, changeFn) {
	if (!jQuery().countDown) {
		ShieldJS.error("检测到元素缺少依赖JS库：countDown.js！");
		return;
	}
	var _default = {
			times: '2019/5/20 00:00:00',  //'2018/8/13 18:00:00'
			days: false,
			ms: false,
			Hour: true,
			msValue: 90, //毫秒间隔
			unit: {
				days: '天',
				hour: '时',
				min: '分',
				second: '秒'
			}
		};
	var options = getExtendSettings(ele, _default);
	ele.countDown(options,function() {
		console.log("初始化错误！！！");
	});	
}

/**
 * 选择器插件
 */
ShieldJS.HtmlAction.addHTMLEleAction("popupSelectPlugin_plugin", ".popupSelectPlugin_plugin", function(contentE, menuliSelect, navMenuSelect, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		dealEle.each(function() {
	        var $this = $(this);
	        
	    	//存在checkFn时contentE为checkFn函数的返回值
	        $this.unbind("click").click(function() {
				var $this = $(this);
				if(hasAttr($this,"confirm")){ //确认信息
					var confirmMsg = $this.attr("confirm"); 
					if(!confirm(confirmMsg)){
						return false;
					}
				}
				var relType; //iframe
				if($this.data("relType")){ //打开类型,data-rel-type
					relType = $this.data("relType");
				}
				var viewTitle = "信息";
				if(hasAttr($this,ShieldJS.css.TITLE)){
					viewTitle = $this.attr(ShieldJS.css.TITLE);
				}
				var viewWidth = 500;
				if(hasAttr($this,ShieldJS.css.WIDTH)){
					viewWidth = $this.attr(ShieldJS.css.WIDTH);
				}
				var viewHeight = 600; //iframe打开时用到
				if(hasAttr($this,ShieldJS.css.HEIGHT)){
					viewHeight = $this.attr(ShieldJS.css.HEIGHT);
				}
				var url = $this.data("url");
				var params = {};
				var checkParams = ShieldJS.HtmlAction.checkAnGetParamSelector($this, params,contentE); //参数选择器
				if (!checkParams) {
					return false;
				} else {
					params = checkParams;
				}
				params = getParams($this,params);
				var successDo = ShieldJS.HtmlAction.successDo.shieldRefresh;
				if (hasAttr($this, "successDo")) { //保存成功后的处理
					successDo = $this.attr("successDo");
				}
				console.log(params);
				ShieldJS.openDialog(url, params, function(ele, dialog) {
					ShieldJS.form.initSubmit(ele, function(formE, targetE, data) {//成功后
						var successDoForm = successDo;
						if (hasAttr(formE, "successDo")) { //form上保存成功后的处理
							successDoForm = formE.attr("successDo");
						}
						if (successDoForm) { //回调
							if (!ShieldJS.HtmlAction.checkSuccessDoMethodExist(successDoForm)) {
								return false;
							} else {
								// 为json格式
								var json;
								if (typeof data == 'object') {
									json = data;
								} else {
									try {
										json = $.parseJSON(data);
									} catch (e) {
										json = '';
									}
								}
								ShieldJS.HtmlAction.execSuccessDoMethod(successDoForm, ShieldJS.contentMainE, searchForm, menuliSelect, dialog, json.refresh, json);
							}
						}
						if (targetE && targetE.is(":visible")) { //未关闭
							ShieldJS.core.bindHtmlAction(targetE, menuliSelect, navMenuSelect, searchForm, dialog); //内部继续加载,已经默认实现
                        }
					 	var options = getSettings($this);
					 	var num = options.num;
						//查找带回
						if($this.hasClass("popupSelectPlugin_plugin")){
						var selectBtnEles = findAndMarkEle(ele, ".selectBtn"); //选择按钮
						var formE =$this.closest('form');
						selectBtnEles.on('click',function(){
							var selectBtnEle = $(this);
							
							if(options.hasOrder)
							{
								
									var thisIndex = formE.find(".popupSelectPlugin_plugin").index($this);
									formE.find(':input.'+options.id).eq(thisIndex).val(selectBtnEle.data("id")).triggerHandler("change");//触发自定义change事件
									var shieldLookupShowNameEle = formE.find('.'+options.name).eq(thisIndex);
									var isInput = shieldLookupShowNameEle.is(":input");
									if(isInput){
										shieldLookupShowNameEle.val(selectBtnEle.data("name"));
									}else{
										shieldLookupShowNameEle.text(selectBtnEle.data("name"));
									}
									shieldLookupShowNameEle.triggerHandler("change");//触发自定义change事件
									
									dialog.remove();
								
							}else
							{
								
								var thisIndex = formE.find(".popupSelectPlugin_plugin").index($this);
								var ids="";
								var names= "";
								
								var length = ele.find(":checkbox[name='id']:checked").length;
								
								if(num!=0&&length>num)
								{
									ShieldJS.alert("title","最多选择"+num+"个！");
									return false;
								}
								ele.find(":checkbox[name='id']:checked").each(function(i){
									if(i==0){
										ids= $(this).data("id");
										names= $(this).data("name");
									}else
									{
										ids=ids+","+$(this).data("id");
										names=names+","+ $(this).data("name");
									}
								})
								if(options.id.indexOf("__")!=-1)
								{
									formE.find(':input.'+options.id).val(ids).triggerHandler("change");//触发自定义change事件
								}else
								{
									formE.find(':input.'+options.id).eq(thisIndex).val(ids).triggerHandler("change");//触发自定义change事件
								}
								var shieldLookupShowNameEle = formE.find('.'+options.name).eq(thisIndex);
								var isInput = shieldLookupShowNameEle.is(":input");
								if(isInput){
									shieldLookupShowNameEle.val(names);
								}else{
									shieldLookupShowNameEle.text(names);
								}
								shieldLookupShowNameEle.triggerHandler("change");//触发自定义change事件
								
								dialog.remove();
							}
						
						
							
						});
					  }
						
					});
					//重新注册，可以使弹出保存的数据回调刷新
					//searchForm = findAndMarkEle(ele, 'form.searchForm');
					//ShieldJS.core.bindHtmlAction(ele, menuliSelect, navMenuSelect,searchForm, dialog); //内部继续加载,已经默认实现
					
				}, viewTitle, viewWidth, viewHeight, null, relType);
				return false;
			});
	        
      });
	}
},"选择器");
//================= 入职勋章插件 ===========================
ShieldJS.HtmlAction.addHTMLEleAction("entryDatePlugin", ".entryDate_plugin", function(contentE, menuli, menu, searchForm, shieldDialog){
	var dealEle = findAndMarkEle(contentE, this.expression);
	if (dealEle.length > 0) {
		if(typeof moment == "undefined"){ //判断lunar是否已经定义
			ShieldJS.error("检测到entryDatePlugin元素缺少依赖JS库：moment.js！");
			return;
		}
		dealEle.each(function() {
	        var $this = $(this);
	        $this.addClass("lv-huiz"); //添加样式防止未加
	        var title = $this.attr("title");
	        if (!title) {
	        	$this.attr("title", "入职年数勋章");
            }
	        var entrydate = $this.data("entrydate");
	        if (entrydate) {
	        	$this.show(); //有日期才显示
	        	var entryYear = new Date(entrydate).getFullYear();
	        	var thisHtml = '';
	        	//var nowYear = new Date().getFullYear();
	        	//var diffYear = nowYear-entryYear+1;
	        	var receivedDate = moment(entrydate); //日期
	        	var diffYears = moment().diff(receivedDate, 'years')+1; //不到1年的为0
	        	thisHtml += '<img id="userInfo" src="' + ctxPath + '/images/ruzhiyear/years';
	        	if ( diffYears <= 2 ) { // 1-2,3-5,6-9,10年以上
	        		thisHtml += '01';
	        	} else if ( diffYears <= 5 ) { // 1-2,3-5,6-9,10年以上
	        		thisHtml += '02';
	        	} else if ( diffYears <= 9 ) { // 1-2,3-5,6-9,10年以上
	        		thisHtml += '03';
	        	} else if ( diffYears > 10 ) { // 1-2,3-5,6-9,10年以上
	        		thisHtml += '04';
	        	}
	        	thisHtml += '.png" alt="" >';
	        	// 工龄1位数 
	        	if ( diffYears < 10 ) { // 1-3,4-6,7-9,10年以上
	        		thisHtml += '<p class="number" style="left:9px; font-size: 16px;">';
	        		thisHtml += diffYears;
	        		thisHtml += '</p>';
                } else if ( diffYears < 100 ) { // 工龄2位数 
                	thisHtml += '<p class="number" style="left:6px; font-size: 13px;">';
	        		thisHtml += diffYears;
	        		thisHtml += '</p>';
				}
	        	$this.html(thisHtml);
            }
		});
	}
}, "入职勋章插件");
